package com.hiep.connect.client.presenter;

import java.util.List;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.hiep.connect.client.event.AddFriendEvent;
import com.hiep.connect.client.event.UserUpdateEvent;
import com.hiep.connect.shared.MyUser;

public class UserSearchResultPresenter implements Presenter {

	public interface UserSearchResultDisplay {
		HasClickHandlers getAddButton();

		// void saveToModel();

		List<MyUser> getSelectedFriends();

		Widget asWidget();
	}

	private UserSearchResultDisplay view;
	private MyUser user;
	private HandlerManager eventBus;

	public UserSearchResultPresenter(MyUser user, HandlerManager eventBus,
			UserSearchResultDisplay view) {
		this.user = user;
		this.eventBus = eventBus;
		this.view = view;

		bind();
	}

	private void bind() {
		// TODO Auto-generated method stub
		this.view.getAddButton().addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				// TODO Auto-generated method stub
				List<MyUser> selectedFriends = view.getSelectedFriends();
				eventBus.fireEvent(new AddFriendEvent(selectedFriends));
			}
		});

	}

	@Override
	public void go(HasWidgets container) {
		// TODO Auto-generated method stub
		container.clear();
		container.add(view.asWidget());
	}

}
